package com.pie4cloud.pie.job.executor.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pie4cloud.pie.job.api.feign.RemoteDispenseCongfigService;
import com.pie4cloud.pie.job.executor.dao.PlaybillMonitorDao;
import com.pie4cloud.pie.jpa.BaseDao;
import com.pie4cloud.pie.jpa.BaseService;
import com.pie4cloud.pie.jpa.page.PageBean;
import com.pie4cloud.pie.jpa.page.PageForm;
import com.pie4cloud.pie.jpa.specification.SimpleSpecificationBuilder;
import com.pie4cloud.pie.job.executor.entity.PlayBillMonitorEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RequiredArgsConstructor
public class PlayBillMonitorService extends BaseService<PlayBillMonitorEntity,Long>  {
	@Autowired
	private PlaybillMonitorDao playbillMonitorDao;


	@Override
	public BaseDao<PlayBillMonitorEntity,Long> getBaseDao() {
		return playbillMonitorDao;
	}
	@Override
	public PlayBillMonitorEntity getById(Long id) {
		return playbillMonitorDao.findById(id).get();
	}

	public PageBean<PlayBillMonitorEntity> page(Page page, PlayBillMonitorEntity playbillEntity) {
		SimpleSpecificationBuilder specificationBuilder = new SimpleSpecificationBuilder();
		Specification specification = specificationBuilder.generateSpecification();
		Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
		PageForm pageForm = new PageForm((int) page.getCurrent(), (int) page.getSize());
		PageBean pageBean = this.getPage(specification, pageForm, sort);
		return pageBean;
	}

	public PlayBillMonitorEntity save(PlayBillMonitorEntity playbillEntity){
		playbillEntity=playbillMonitorDao.saveNotNull(playbillEntity);
        return playbillEntity;
	}

	public PlayBillMonitorEntity update(PlayBillMonitorEntity playbillEntity){
		playbillEntity=playbillMonitorDao.saveNotNull(playbillEntity);
		return playbillEntity;
	}

	public Boolean removeById(Long id) {
		playbillMonitorDao.deleteById(id);
		return true;
	}

	public PlayBillMonitorEntity findByTimeLevelAndDdataClassId(Date timeLevel, String ddataClassId){
		return playbillMonitorDao.findByTimeLevelAndDdataClassId(timeLevel,ddataClassId);
	}

	public PlayBillMonitorEntity findByTimeLevelAndPlayBillId(Date timeLevel,Long playBillId){
		return playbillMonitorDao.findByTimeLevelAndPlayBillId(timeLevel,playBillId);
	}
}
